package Sock;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class time2 {
    public static void main(String[] args) throws IOException {
        ServerSocket socket=new ServerSocket(8888);
        Socket socket1=socket.accept();
        InputStream buf=socket1.getInputStream();
        int n=0;
        byte[] bytes=new byte[1024];
        while ((n= buf.read(bytes))!=-1){
            System.out.println("收到"+new String(bytes,0,n));
        }
        socket1.shutdownInput();

        String s=LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd:mm:ss"));
        OutputStream buf1=socket1.getOutputStream();
        buf1.write(s.getBytes());
        socket1.shutdownOutput();

        buf.close();
        buf1.close();
        socket.close();
    }
}
